/*
 * @Author: panghu chenjh@datamargin.com
 * @Date: 2024-03-27 08:52:34
 * @LastEditors: panghu chenjh@datamargin.com
 * @LastEditTime: 2024-03-27 14:47:01
 * @FilePath: \vue3-vite-mall-admin-system\src\store\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { createStore } from 'vuex'
import {
  getUserInfoApi
} from '@/api/login.js'
const store = createStore({
  state() { 
    return {
      userInfo: {}, // 用户信息
      menus: [], // 侧边栏菜单
      isCollapse: false, // 侧边栏是否收缩
    }
  },
  mutations: {
    SET_USERINFO(state, data) { 
      state.userInfo = data
      state.menus= data.menus
    },
    SET_ISCOLLAPSE(state) {
      state.isCollapse = !state.isCollapse
    }
  },
  actions: {
    getUserInfo(store) { 
      return new Promise((resolve, reject) => { 
        getUserInfoApi().then(res => {
          store.commit('SET_USERINFO', res.data)
          resolve(res)
        }).catch(err => reject(err))
      })
    }
  }
})

export default store